package com.d0325;

import java.time.*;
import java.time.format.DateTimeFormatter;

public class TestDateTimeFormatter {
    public static void main(String[] args) {
        //创建DateTimeFormatter对象
        DateTimeFormatter dtf1=DateTimeFormatter.ofPattern("yyyy/MM/dd");
        DateTimeFormatter dtf2=DateTimeFormatter.ofPattern("HH时mm分ss秒");
        DateTimeFormatter dtf3=DateTimeFormatter.ofPattern("yyyy/MM/dd hh时mm分ss秒");

        //创建LocalDate、LocalTime、LocalDatetime对象
        LocalDate date=LocalDate.now();
        LocalTime time=LocalTime.now();
        LocalDateTime datetime=LocalDateTime.now();

		//进行格式化
        System.out.println(date.format(dtf1));
        System.out.println(time.format(dtf2));
        System.out.println(datetime.format(dtf3));

        //使用DateTimeFormatter对象进行转换
        String str1="2001/12/03";
        String str2="12时23分34秒";
  //      String str3="2001/12/03T12:23:34";
        LocalDate date2=LocalDate.parse(str1,dtf1);
        LocalTime time2=LocalTime.parse(str2,dtf2);
     //   LocalDateTime datetime2=LocalDateTime.parse(str3,dtf3);
        System.out.println(date2);
        System.out.println(time2);
//        System.out.println(datetime2);

    }
}
